package main;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.HashMap;
import java.util.Map;
import network.NetworkListener;
import objects.Player;




public enum GameEngine implements KeyListener, NetworkListener
{
   INSTANCE;
   private final Map<Integer, Player> players = new HashMap<>();

   @Override
   public void keyTyped(KeyEvent e)
   {}

   @Override
   public void keyPressed(KeyEvent e)
   {}

   @Override
   public void keyReleased(KeyEvent e)
   {}
   
   @Override
   public void onPlayerLogin(int objId, int x, int y)
   {
      Player p = new Player(objId, x, y);
      if (INSTANCE.players.isEmpty()) {
	 INSTANCE.players.put(objId, p);
	 GameMain.addKeyListener(p);
      } else
	 INSTANCE.players.put(objId, p);
   }

   @Override
   public void onPlayerMove(int objId, int x, int y)
   {
      if (players.containsKey(objId)) players.get(objId).onPlayerMove(objId, x, y);
   }
}
